package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-04-04 00:21
 */
public class QLint415 {
    public boolean isPalindrome(String s) {
        if(s == null || s.length() == 0) {
            return true;
        }

        int i = 0, j = s.length() - 1;
        while(i < j) {
            while(i < j && isNotValid(s.charAt(i))) {
                i++;
            }
            while(i < j && isNotValid(s.charAt(j))) {
                j--;
            }

            if(i < j && Character.toLowerCase(s.charAt(i)) != Character.toLowerCase(s.charAt(j))) {
                return false;
            }
            i++;
            j--;
        }

        return true;
    }

    private boolean isNotValid(char ch) {
        return !Character.isLetter(ch) && !Character.isDigit(ch);
    }

    public static void main(String[] args) {
        System.out.println(new QLint415().isPalindrome("ab"));
    }
}
